<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				编辑信息
			</block>
		</cu-custom>
		<a-lists :keys="keys" :value="parm">
			<template #password="{row,index,value}">
				<a-button @click='showForm = true'>重置密码</a-button>
			</template>
			<template #weixing="{row,index,value}">
				<a-button @click="weixing">微信解绑</a-button>
			</template>
			<template #lock="{row,index,value}">
				<a-button @click="openLock">账号解锁</a-button>
			</template>
		</a-lists>
		<a-popup v-model="showForm">
			<y-form :keys="columns" v-model="info" @submit="submit" submitText="重置" />
		</a-popup>
	</view>
</template>

<script>
	import yForm from "@/y-ui/y-form/y-form.vue";
	export default {
		components: {
			yForm
		},
		onLoad(e) {
			this.parm = e;
		},
		data() {
			return {
				showForm:false,
				parm: {},
				info:{},
				keys: [{
						lable: '姓名',
						key: "name"
					},
					{
						lable: '登录名',
						key: "1"
					}, {
						lable: '部门',
						key: "2"
					}, {
						lable: '手机号',
						key: "telephone"
					},
					{
						slot:'password'
					},
					{
						slot:'weixing'
					},
					{
						slot:'lock'
					}
				],
				columns:[
					{
						type: 'password',
						key: 'password',
						lable: '新密码：',
						placeholder:"请输入新密码",
						rules: {
							rule: ['required'],
							msg: ['请输入']
						}
					},
					{
						type: 'password',
						key: 'password1',
						lable: '确认新密码：',
						placeholder:"请确认新密码",
						rules: {
							rule: ['required'],
							msg: ['请输入']
						}
					}
				]
			}
		},
		methods: {
			async weixing(){
				await this.prompt(`确定解绑${this.parm.name}老师吗？`);
				//解绑微信接口
				await this.$http.post('',{id:this.parm.id}).finally(this.$loading({msg:"解绑中"}));
				uni.showToast({
					title:"解绑成功！"
				});
			},
			async openLock(){
				await this.prompt(`确定解锁${this.parm.name}老师吗？`);
				//解锁接口
				await this.$http.post('',{id:this.parm.id}).finally(this.$loading({msg:"解锁中"}));
				uni.showToast({
					title:"解锁成功！"
				});
			},
			//密码重置
			submit(e){
				if(!e) return ;
				if(this.info.password != this.info.password1){
					this.prompt('提示',"两次密码不一致，请重新输入",false);
					return ;
				}
				//密码重置接口
				this.$http.post('',this.info).then(res=>{
					uni.showToast({
						title:"密码重置成功"
					})
				}).finally(this.$loading({msg:"密码重置中"}));
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		display: flex;
		align-items: center;
		padding: 15px;
		color: #000;
		font-size: 18px;
		position: relative;

		&::after {
			content: '';
			position: absolute;
			left: 10px;
			right: 0;
			bottom: 0;
			transform: scaleY(.3);
			border-bottom: 1px solid rgba(0, 0, 0, .2);
		}

		.value {
			color: #999999;
			flex: 1;
			text-align: right;
		}
	}
</style>
